//
//  ByRechargeModuleView.m
//  caipiao_ios
//
//  Created by mc on 2018/7/9.
//  Copyright © 2018年 ZhangZhanbin. All rights reserved.
//

#import "ByRechargeModuleView.h"
#import "ByDottedLineView.h"


@implementation ByRechargeModuleView

- (id)init{
    self = [super init];
    if (self) {
        
    }
    return self;
}

- (void)setDataArray:(NSArray *)dataArray{
    _dataArray = dataArray;
    [self.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    CGFloat left = 10;
    CGFloat interval = 18;
    self.index = 0;
    CGFloat width = (SCREEN_WIDTH - left * 2 - interval * 3) / 4.0;
    CGFloat height = 40;
    for (int i = 0; i < dataArray.count; i++) {
        ByDottedLineSecondBorderButton *btn = [ByDottedLineSecondBorderButton buttonWithType:UIButtonTypeCustom];
        [btn setTitle:[NSString stringWithFormat:@"%@元", _dataArray[i]] forState:UIControlStateNormal];
        [btn.titleLabel setFont:[UIFont systemFontOfSize:14]];
        [btn setTitleColor:BY_THEME_COLOR forState:UIControlStateNormal];
        btn.frame = CGRectMake(left + i % 4 * (interval + width) + i , i / 4 * (interval + height), width, height);
        [self addSubview:btn];
        [btn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
        btn.tag = 100 + i;
        if (i == 0) {
            btn.backgroundColor = BY_THEME_COLOR;
            [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        }
    }
}

- (void)btnAction:(UIButton *)btn{
    if (btn.tag == self.index + 100) {
        return;
    }else{
        ByDottedLineSecondBorderButton *btn1 = [self viewWithTag:self.index + 100];
        btn1.backgroundColor = [UIColor whiteColor];
        [btn1 setTitleColor:BY_THEME_COLOR forState:UIControlStateNormal];
        
        self.index = btn.tag - 100;
        btn.backgroundColor = BY_THEME_COLOR;
        btn.layer.masksToBounds = YES;
        [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        
        if (self.selectValueBlock) {
            self.selectValueBlock(self.index);
        }
    }
}


@end
